package com.hanhy.test;

import com.hanhy.Page.IndexPage;
import com.hanhy.Page.LoginPage;
import com.hanhy.util.ConfigUtil;
import com.hanhy.util.DriverFactory;
import com.hanhy.util.Log;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.os.WindowsUtils;
import org.testng.Assert;
import org.testng.annotations.Test;

/**
 * Created by Administrator on 2016/12/12.
 * 测试用例：
 * 1、首页可以成功进入应用
 * 2、竞价应用可以打开新建竞价页面
 */
public class BidProjectIndex {

    public WebDriver driver = null;
    protected IndexPage indexPage = null;
    public static Log log = new Log(BidProjectIndex.class);


//    @Test(description = "通过URL进入竞价项目")
    public void getIntoBidIndex() {
        WindowsUtils.getProgramFilesPath();
        try {
            if(indexPage.getGreetingText().contains("欢迎您")){
                log.info(indexPage.getIntoBidIndexByUrl().currentUrl());
                Assert.assertTrue(indexPage.getIntoBidIndexByUrl().currentUrl().contains(ConfigUtil.getConstantValue("bid_indexUrl_part")));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

//    @Test(description = "进入新建竞价单页面", dependsOnMethods = {"getIntoBidIndex"})
//    public void getIntoBidCreate() {
//        try {
//            BidIndexPage bidIndexPage = new BidIndexPage(this.driver);
//            CreateBidProjectPage createBidProject = bidIndexPage.getIntoCreatePage();
//            Assert.assertTrue(createBidProject.currentUrl().contains(ConfigUtil.getConstantValue("bid_createUrl_part")));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }

//    @Test(description = "建立打包采购项目：背靠背竞价",dependsOnMethods = {"getIntoBidCreate"})
    public void createBidProject(){

    }

    public  WebDriver getDriver(){
        return this.driver;
    }


//    @AfterTest(description = "测试完成，关闭浏览器")
//    public void afterTest() {
//        this.driver.close();
//    }

    @Test(description = "初始化全局driver")
    public void beforeTest() {
        driver = DriverFactory.getFirefoxDriver();
        if (driver == null) {
            throw new ExceptionInInitializerError("driver初始化失败");
        }
        try {
            log.info(ConfigUtil.getConstantValue("LOGIN_URL"));
            LoginPage loginPage = new LoginPage(this.driver,ConfigUtil.getConstantValue("LOGIN_URL"));
//            indexPage = loginPage.login(ConfigUtil.getConstantValue("userName"), ConfigUtil.getConstantValue("password"));
            indexPage = loginPage.login("cgs0708bhhy","hhy1234");
        } catch (Exception e) {
            log.debug(e.getMessage());
        }
    }

    }


